You can write to a file in Node.js using the fs.writeFile() method. Here's an example:
How would you write a JSON config object to a file called config.json?
What happens if you call fs.writeFile on a path that's actually a directory?
Why might you use writeFileSync in a CLI startup script instead of the async version?
You're adding a request logger that appends to a file. The app crashes and the last few log lines are missing. What went wrong?
A teammate used fs.writeFileSync inside an Express route handler. Why is that problematic under load?
How would you implement atomic writes so a reader never sees a half-written file?
Design a file-based cache that handles concurrent writes from multiple worker processes without corruption.
Your service streams large CSV exports to disk. Users report memory spikes during export. How do you fix it?
How would you implement log rotation (daily files, max 30 days) without losing log entries during the rotation moment?
We're migrating from local filesystem writes to S3. How do you design the abstraction layer so callers don't change?
Multiple services write to a shared NFS mount. How do you prevent corruption and ensure consistency?
Design a write-ahead log for a custom embedded database engine — durability, recovery, and compaction.